/*
* SuctionSumController.java
* Created on  2015/7/21 10:30
* 版本       修改时间          作者      修改内容
* V1.0.1    2015/7/21       longshihui    初始版本
*
*/

package com.infitecs.eyas.suction;

import com.infitecs.eyas.expression.service.ExpressionService;
import com.infitecs.eyas.session.SessionService;
import com.infitecs.eyas.session.model.Param;
import com.infitecs.eyas.suction.model.SuctionDes;
import com.infitecs.eyas.suction.model.SuctionSummary;
import com.infitecs.eyas.suction.service.SuctionDesService;
import com.infitecs.eyas.suction.service.SuctionSummaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 类的描述信息
 *
 * @author longshihui
 * @version 1.0.1
 */
@Controller
@RequestMapping("/suction/summary")
public class SuctionSumController {

    @Autowired
    private SessionService sessionService;


    @Autowired
    private ExpressionService expressionService;

    @Autowired
    private SuctionSummaryService suctionSummaryService;

    @Autowired
    private SuctionDesService suctionDesService;

    @RequestMapping("")
    public String getPage(){
        try {
            sessionService.getCaseId();
            SuctionSummary suctionSummary = suctionSummaryService.getSuctionSummary();
            if (suctionSummary == null) {
                suctionSummaryService.insertNewSummary();
            }
        } catch (Exception e) {
            return "suction/summary";
        }
        sessionService.setEnvironment('Y');
        return "suction/summary";
    }

    @RequestMapping(value = "/getCalculateInit",method = RequestMethod.POST)
    @ResponseBody
    public void getCalculateInit() {
        sessionService.putSuctionSummaryInit(sessionService.getCaseId());
    }

    @RequestMapping(value = "/getAutoCalculate", method = RequestMethod.POST)
    @ResponseBody
    public SuctionSummary getAutoCalculate() {
        Map<String,Double> map = sessionService.getParamMap();
        SuctionSummary suctionSummary = new SuctionSummary();
        SuctionDes suctionDes = suctionDesService.getOnceFanDes();
        if (null != suctionDes) {
            suctionSummary.setE9(suctionDes.getE9());
            suctionSummary.setE52(suctionDes.getE52());
            suctionSummary.setE67(suctionDes.getE66());
            map.put("YE67",suctionDes.getE66());
        }
        suctionSummary.setE41(expressionService.calculate(new Param("YE41")));
        suctionSummary.setE42(expressionService.calculate(new Param("YE42")));
        suctionSummary.setE45(expressionService.calculate(new Param("YE45")));
        suctionSummary.setE47(expressionService.calculate(new Param("YE47")));
        suctionSummary.setE50(expressionService.calculate(new Param("YE50")));
        suctionSummary.setE53(expressionService.calculate(new Param("YE53")));
        suctionSummary.setE55(expressionService.calculate(new Param("YE55")));
        suctionSummary.setE56(expressionService.calculate(new Param("YE56")));
        suctionSummary.setE60(expressionService.calculate(new Param("YE60")));
        suctionSummary.setE61(expressionService.calculate(new Param("YE61")));
        suctionSummary.setE62(expressionService.calculate(new Param("YE62")));
        suctionSummary.setE63(expressionService.calculate(new Param("YE63")));
        suctionSummary.setE65(expressionService.calculate(new Param("YE65")));
        suctionSummary.setE68(expressionService.calculate(new Param("YE68")));
        suctionSummary.setE69(expressionService.calculate(new Param("YE69")));
        suctionSummary.setE43(map.get("YE43"));
        suctionSummary.setE44(map.get("YE44"));
        suctionSummary.setE46(map.get("YE46"));
        suctionSummary.setE48(map.get("YE48"));
        suctionSummary.setE49(map.get("YE49"));
        suctionSummary.setE41(map.get("YE41"));
        suctionSummary.setE51(map.get("YE51"));
        suctionSummary.setE57(map.get("YE57"));
        suctionSummary.setE58(map.get("YE58"));
        suctionSummary.setE59(map.get("YE59"));
        suctionSummary.setE61(map.get("YE61"));
        suctionSummary.setE64(map.get("YE64"));
        suctionSummary.setE66(map.get("YE66"));
        suctionSummary.setE68(map.get("YE68"));
        return suctionSummary;
    }
}
